﻿NAMFox.ns(function() { with (NAMFox) {

name("Big Integer Tests");

//////////////////////////////////////////////
// Test Cases
//////////////////////////////////////////////

test("Supports Small Values", function() {
    var sut = new BigInteger("FF");
            
    equals(
        "ff",
        sut.toString(),
        "The big integer with a small value must equal its counterpart array.");
    
    sut = new BigInteger("0D5A");
    
    equals(
        "d5a",
        sut.toString(),
        "The big integer with a small value must equal its counterpart array.");
});

test("Supports Large Values", function() {
    var sut = new BigInteger("F234567890ABCDEF");
            
    equals(
        "f234567890abcdef",
        sut.toString(),
        "The big integer with a large value must equal its counterpart array.");
    
    sut = new BigInteger("100FF");
    
    equals(
        "100ff",
        sut.toString(),
        "The big integer with a large value must equal its counterpart array.");
    
    sut = new BigInteger("FFFFFFFFFFFFFFFF");
    
    equals(
        "ffffffffffffffff",
        sut.toString(),
        "The big integer with a large value must equal its counterpart array.");
});

test("Supports Equals", function() {
    var sut = new BigInteger("ABCD");
            
    ok(
        sut.equals(new BigInteger("abcd")),
        "The big integer 0xabcd must equal itself.");
    ok(
        sut.equals("abcd"),
        "The big integer 0xabcd must equal itself.");
    
    sut = new BigInteger("1234567890ABCDEF");
    ok(
        sut.equals(new BigInteger("1234567890abcdef")),
        "The big integer 0x1234567890ABCDEF must equal itself.");
    ok(
        sut.equals("1234567890abcdef"),
        "The big integer 0x1234567890ABCDEF must equal itself.");
});

test("Supports Not Equals", function() {
    var sut = new BigInteger("ABCD");
            
    ok(
        !sut.notEquals(new BigInteger("abcd")),
        "The big integer 0xabcd must equal itself.");
    
    sut = new BigInteger("1234567890ABCDEF");
    ok(
        !sut.notEquals(new BigInteger("1234567890abcdef")),
        "The big integer 0x1234567890ABCDEF must equal itself.");
    
    sut = new BigInteger("1234567890ABCDEF");
    ok(
        sut.notEquals(new BigInteger("1234567890abcdee")),
        "The big integers 0x1234567890ABCDEF and 0x1234567890abcdee must not equal each other.");
    
    sut = new BigInteger("80000000");
    ok(
        sut.notEquals(new BigInteger("70000000")),
        "The big integers 0x80000000 and 0x70000000 must not equal each other.");
    
    ok(
        sut.notEquals(0),
        "The big integers 0x80000000 and 0x0 must not equal each other.");
    
    ok(
        !sut.notEquals("80000000"),
        "The big integers 0x80000000 and 0x0 must not equal each other.");
});

test("Supports Bitwise And", function() {
    var sut = new BigInteger("FF");
            
    equals(
        "ff",
        sut.bitwiseAnd(new BigInteger("FF")).toString(),
        "0xFF & 0xFF must equal 0xFF");
    
    equals(
        "0",
        sut.bitwiseAnd(new BigInteger("F0000")).toString(),
        "0xFF & 0xF0000 must equal 0x0");
    
    sut = new BigInteger("912345678");
    
    equals(
        "12345678",
        sut.bitwiseAnd(new BigInteger("1FFFFFFF")).toString(),
        "0x912345678 & 0x1FFFFFFF must equal 0x12345678");
});

test("Supports Bitwise And Not", function() {
    var sut = new BigInteger("FF");

    equals(
        "0",
        sut.bitwiseAndNot(new BigInteger("FF")).toString(),
        "0xFF & ~0xFF must equal 0x0");
    
    equals(
        "ff",
        sut.bitwiseAndNot(new BigInteger("F0000")).toString(),
        "0xFF & ~0xF0000 must equal 0xFF");
    
    sut = new BigInteger("912345678");
    
    equals(
        "900000000",
        sut.bitwiseAndNot(new BigInteger("1FFFFFFF")).toString(),
        "0x912345678 & ~0x1FFFFFFF must equal 0x900000000");
    
    sut = new BigInteger("10000000");
    
    equals(
        "0",
        sut.bitwiseAndNot(new BigInteger("10000000")).toString(),
        "0x10000000 & ~0x10000000 must equal 0x0");
});

test("Supports Bitwise Or", function() {
    var sut = new BigInteger("00");

    equals(
        "12",
        sut.bitwiseOr(new BigInteger("12")).toString(),
        "0x0 | 0x12 must equal 0x12");
    
    equals(
        "f0000",
        sut.bitwiseOr(new BigInteger("F0000")).toString(),
        "0x0 | 0xF0000 must equal 0xF0000");
    
    sut = new BigInteger("912345678");
    
    equals(
        "91fffffff",
        sut.bitwiseOr(new BigInteger("1FFFFFFF")).toString(),
        "0x912345678 | 0x1FFFFFFF must equal 0x91FFFFFFF");

    sut = new BigInteger("1");

    equals(
        "3",
        sut.bitwiseOr("2").toString(),
        "0x1 | 0x2 must equal 0x3");
});

test("Supports creation from multiple of two", function() {
    equals(
        "1",
        BigInteger.fromMultipleOfTwo(0).toString(),
        "2^0 = 0x1");

    equals(
        "2",
        BigInteger.fromMultipleOfTwo(1).toString(),
        "2^1 = 0x2");

    equals(
        "4",
        BigInteger.fromMultipleOfTwo(2).toString(),
        "2^2 = 0x4");

    equals(
        "8",
        BigInteger.fromMultipleOfTwo(3).toString(),
        "2^3 = 0x8");

    equals(
        "10",
        BigInteger.fromMultipleOfTwo(4).toString(),
        "2^4 = 0x10");

    equals(
        "20",
        BigInteger.fromMultipleOfTwo(5).toString(),
        "2^5 = 0x20");

    equals(
        "8000000000000000",
        BigInteger.fromMultipleOfTwo(63).toString(),
        "2^63 = 0x8000000000000000");
});

}});